﻿using System;
using BugSense;
using Microsoft.Phone.Tasks;

namespace Kiva7.Utilities
{
    public static class ExceptionHandler
    {
        public static void EmailException(Exception ex)
        {
            EmailComposeTask email = new EmailComposeTask
                {
                    To = "kiva7@live.com",
                    Subject = "Kiva7 Exception: " + ex.Message
                };

            string body = "";

            Exception parentEx = ex;
            while (parentEx != null)
            {
                body += ex.Message;
                body += "\n";

                body += ex.StackTrace;
                body += "\n\n";

                parentEx = ex.InnerException;
            }

            email.Body = body;

            email.Show();
        }

        public static void HandleException(Exception ex)
        {
            try
            {
                BugSenseHandler.Instance.LogError(ex);
            }
// ReSharper disable EmptyGeneralCatchClause
            catch
// ReSharper restore EmptyGeneralCatchClause
            {
                // if logging fails do not throw that exception
            }
        }
    }
}
